package com.net.xpay.stat.scheduler;


import com.net.xpay.common.helper.NoticeHelper;
import com.net.xpay.common.service.PartnerInsiderSettleLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * 2019/7/15 16:28

 * 结算合伙人佣金
 */
@Slf4j
@Component
public class PartnerInsiderSettleLogScheduler {

    @Autowired
    private PartnerInsiderSettleLogService partnerInsiderSettleLogService;


    @Autowired
    private NoticeHelper noticeHelper;

    /**
     * 每月1号日8点 更新数据 BASE：该统计基于UserTransMonthStat和UserSafePayTransMonth的统计数据
     */
    @Scheduled(cron = "0 0 8 1 * *")
    public void doPartnerInsiderSettleLog() {
        try {
            long t1 = System.currentTimeMillis();
            int count = 1;//最近1个月
            while (count > 0) {
                log.info("start schedule doPartnerInsiderSettleLog|now={}", LocalDateTime.now());
                LocalDateTime now = LocalDateTime.now().minusMonths(count);
                partnerInsiderSettleLogService.doPartnerInsiderSettleLog(now.getYear(), now.getMonthValue());
                long t2 = System.currentTimeMillis();
                log.info("end schedule doPartnerInsiderSettleLog|now={}|cost={}", LocalDateTime.now(), t2 - t1);
                noticeHelper.sendSystemInfoNotice("内部员工结算数据生成完成，耗费时间：" + (t2 - t1), "text");
                count--;
            }
        } catch (Throwable e) {
            log.warn("doPartnerInsiderSettleLog error", e);
            noticeHelper.sendSystemMonitorNotice("内部员工结算数据失败|doPartnerInsiderSettleLog error", "text");
        }
    }









}
